<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>权限列表</title>
</head>
<body>

<div class="ebsig_container">
    <div class="comm_content">
        <div  class="search-box">
            <div style="position:relative">
                <form class="form-inline" id="searchForm">
                    <table>
                        <tr>
                            <td>
                                <span>
                                    权限组名称：
                                    <select class="form-control w150" id="s_permissionGroupID" name="s_permissionGroupID">
                                        <option value="">请选择</option>
                                        <!--{foreach from=$permission_group_array item=groupList}-->
                                        <option value="<!--{$groupList.permissionGroupID}-->"><!--{$groupList.permissionGroupName}--></option>
                                        <!--{/foreach}-->
                                    </select>
                                </span>
                                <span><input type="button" class="btn btn-primary" value="查询" onclick="permission.search();"></span>
                                <span><input type="button" class="btn btn-warning" value="重置" onclick="permission.reset();"></span>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>

        <table id="flex" style="display:none"></table>

    </div>
</div>

<div id="pop" style="display: none;">

    <form class="form-horizontal" id="addForm" onsubmit="return false;">

        <div class="form-group">
            <label for="permissionID" class="col-sm-2 control-label"><span class="red">*</span> 权限号：</label>
            <div class="col-sm-10">
                <input type="text" class="form-control w300" id="permissionID" name="permissionID" placeholder="请输入权限号">
            </div>
        </div>

        <div class="form-group">
            <label for="permissionName" class="col-sm-2 control-label"><span class="red">*</span> 权限名称：</label>
            <div class="col-sm-10">
                <input type="text" class="form-control w300" id="permissionName" name="permissionName" placeholder="请输入权限名称">
            </div>
        </div>

        <div class="form-group">
            <label for="permissionGroupID" class="col-sm-2 control-label"><span class="red">*</span> 权限组：</label>
            <div class="col-sm-10">

                <select class="form-control w150 fl" name="permissionGroupID" id="permissionGroupID" onchange="permission.group()">
                    <option value="" selected>请选择</option>
                    <!--{foreach from=$permission_group_array item=groupList}-->
                    <option value="<!--{$groupList.permissionGroupID}-->"><!--{$groupList.permissionGroupName}--></option>
                    <!--{/foreach}-->
                    <option value="-1">新建权限组</option>
                </select>
                <input type="text" class="form-control w150" id="newGroup" name="newGroup" style="display: none;" placeholder="请输入权限组名" />
            </div>
        </div>

        <div class="form-group">
            <label for="permissionRequest" class="col-sm-2 control-label"><span class="red">*</span> 权限路径：</label>
            <div class="col-sm-10">
                <input type="text" class="form-control w500" id="permissionRequest" name="permissionRequest" placeholder="请输入权限路径">
                <input type="hidden" name="uuid" id="uuid" value="0" />
            </div>
        </div>

    </form>

</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/project/permission.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "操作", width : 50, align: 'center'},
            {display: "权限ID", name : "permissionID" , width : 80 , sortable : true },
            {display: "权限名", width : 100},
            {display: "权限组名称", width : 100},
            {display: "权限URL", width : 400}
        ],
        buttons : [
            {name: "添加", bclass: "add", onpress : "permission.edit"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "permission.del.check"},
            {separator: true},
            {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
            {separator: true},
            {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
        ],
        sortname: "permissionID",
        sortorder: "ASC",
        usepager: true,
        rp: 10,
        useRp: true,
        query: '',
        showTableToggleBtn: true
    });

    var permission = {

        search: function() {
            var dt = $("#searchForm").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },

        reset: function() {
            $('#s_permissionGroupID').val('');
            this.search();
        },

        permissionID: '',

        edit: function( permissionID ) {

            E.loadding.open('正在加载，请稍候...');
            var name ="";

            if (permissionID) {
                this.permissionID = permissionID;
                name = "修改权限";
                E.ajax_get({
                    url: "/invokingAjax-backend/project/permission.ajax?operFlg=2",
                    data:{
                        permissionID: permissionID
                    },
                    call: "permission.permissionEdit"
                });
                E.loadding.close();
            }else{
                this.permissionID = '';
                name = "新增权限";
                E.loadding.close();
            }
            E.popup.open({
                id:"pop",
                title: name,
                css: "width:700px;",
                btnName: "提交",
                btnCall:"permission.check();" //
            });

        },

        //编辑页面弹出框
        permissionEdit: function(o) {
            if( o == null ){
                E.alert('没有找到信息');
                return false;
            }
            $("input[name=permissionID]").val(o.permissionID);
            $("input[name=permissionName]").val(o.permissionName);
            $("input[name=permissionRequest]").val(o.permissionRequest);
            $("#permissionGroupID").val(o.permissionGroupID);
            $("#uuid").val(o.uuid);
        },

        check:function(){

            var error_msg = "";
            this.dt = E.getFormValues("addForm");

            if (!E.isInt(this.dt.permissionID) || this.dt.permissionID <= 0) {
                error_msg += "请输入权限号<br>";
            }

            if (E.isEmpty(this.dt.permissionName)) {
                error_msg += "请输入权限名称<br>";
            }

            if (this.dt.permissionGroupID == 0) {
                error_msg += "请选择权限组<br>";
            } else if (this.dt.permissionGroupID == -1 && E.isEmpty(this.dt.newGroup)) {
                error_msg += "请输入新权限组名称<br>";
            }

            if (E.isEmpty(this.dt.permissionRequest)) {
                error_msg += "请输入权限路径<br>";
            }

            if (error_msg != "") {
                E.alert(error_msg);
            } else {
                E.loadding.open("正在保存权限，请稍候...");
                E.ajax_post({
                    url: "/invokingAjax-backend/project/permission.ajax?operFlg=100&act=edit",
                    data: this.dt,
                    call: "permission.result"
                });
            }

        },

        result: function( o ) {

            E.loadding.close();
            if (o.code == 200) {
                permission.load();
                if (this.permissionID) {
                    E.alert(o.message, 2, "E.popup.close");
                } else {
                    E.alert(o.message, 2);
                    $("input[name=permissionID]").val("");
                    $("input[name=permissionName]").val("");
                    $("input[name=permissionRequest]").val("");
                    $("#permissionGroupID").val("");
                }
            } else {
                E.alert(o.message);
            }

        },

        del: {

            p_array: "",

            check: function() {

                if ($(".trSelected",flex).length == 0) {
                    E.alert("请选择要删除的权限");
                } else {
                    var permission_array = new Array();
                    //循环选中的行
                    $(".trSelected",flex).each(function(k, v){
                        permission_array.push($(v).attr("id").substr(3));
                    });
                    this.p_array = permission_array;
                    //弹出确认层
                    E.confirm("您确认要删除选择的权限吗？", "permission.del.execute");
                }

            },

            execute: function() {
                E.loadding.open("正在删除权限，请稍候...");
                E.ajax_get({
                    url: "/invokingAjax-backend/project/permission.ajax?operFlg=100&act=del",
                    data: {
                        p_array: this.p_array
                    },
                    call: "permission.del.result"
                });
            },

            result: function( o ) {

                E.loadding.close();
                if (o.code == 200) {

                    E.alert(o.message, 2, "permission.load");

                } else {

                    E.alert(o.message);

                }
            }

        },

        load: function() {
            $("#flex").flexReload();
        },

        group: function(){

            if($("#permissionGroupID").val() == -1){
                $("#newGroup").show();
            }else {
                $("#newGroup").hide().val("");
            }
        }

    };


</script>
</body>
</html>